//
//  StatusCell.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/11/20.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "StatusCell.h"
#import "StatusCellOriginalView.h"


@implementation StatusCell

-(StatusCellOriginalView *)statusCellOriginalView{
    
    return _statusCellOriginalView;
}

-(StatusCellBottomView *)statusCellBottomlView{
    
    return _statusCellBottomlView;
}

-(void)setStatus:(Status *)status{
    
    self.statusCellOriginalView.status = status;
    
    [self.bottomViewTopConstaint uninstall];
    if (status.retweeted_status != nil) {
        self.statusRetweetedView.retweetedStatus = status.retweeted_status;
        
        [_statusCellBottomlView  mas_updateConstraints:^(MASConstraintMaker *make) {
           self.bottomViewTopConstaint = make.top.equalTo(_statusRetweetedView.mas_bottom);
        }];
        
        _statusRetweetedView.hidden = false;
    }else{
        
        [_statusCellBottomlView  mas_updateConstraints:^(MASConstraintMaker *make) {
            self.bottomViewTopConstaint = make.top.equalTo(_statusCellOriginalView.mas_bottom);
        }];
       _statusRetweetedView.hidden = true;
    }
    
//    可能赋值有问题???
    NSLog(@"self.statusRetweetedView.retweetedStatus  = %@",self.statusRetweetedView.retweetedStatus);
}
//xib加载的话才会走这个方法
- (void)awakeFromNib {
    [super awakeFromNib];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    [self setupUI];
//    cell的选中样式
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    return self;
}

- (void)setupUI{
    StatusCellOriginalView *statusOriginalView = [[StatusCellOriginalView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    StatusCellBottomView *statusBottomView = [[StatusCellBottomView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    StatusRetweetedView *RetweetedView = [[StatusRetweetedView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.statusCellOriginalView = statusOriginalView;
    self.statusCellBottomlView = statusBottomView;
    self.statusRetweetedView = RetweetedView;
    [self.contentView addSubview:_statusCellOriginalView];
    [self.contentView addSubview:_statusCellBottomlView];
    [self.contentView addSubview:_statusRetweetedView];
    
    [_statusCellOriginalView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(self.contentView);
    }];
    
    [_statusCellBottomlView mas_makeConstraints:^(MASConstraintMaker *make) {
        
#pragma mark :问题从这里开始被发现,问题就是_statusRetweetedView可能是空的,所有要进行上面的set方法里面的判断,以及对约束的重新布局
       self.bottomViewTopConstaint = make.top.mas_equalTo(_statusRetweetedView.mas_bottom);
        make.left.right.mas_equalTo(self.contentView);
        make.height.mas_equalTo(35);
    }];
    
    [_statusRetweetedView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_statusCellOriginalView);
        make.top.equalTo(_statusCellOriginalView.mas_bottom);
//        注意底部的约束在自己内部相对于label已经进行了约束
    }];
//    设置StatusCell的行高约束
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.right.equalTo(self);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(_statusCellBottomlView.mas_bottom);
    }];
}
@end
